package org.example.config;


import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.example.provider.AiChatAgentMemoryProvider;
import org.example.provider.MongdbChatMemoryProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 聊天记忆提供者配置--配置指定义的记忆存储器
 */
@Configuration
public class ChatMemoryProviderConfig {

    @Autowired
    private MongdbChatMemoryProvider mongdbChatMemoryProvider;

    @Autowired
    private AiChatAgentMemoryProvider aiChatAgentMemoryProvider;


    // 创建一个聊天记忆提供者，用于创建聊天记忆,区分聊天记忆
    @Bean
    public ChatMemoryProvider charMemoryProvider() {
        return memoryId -> MessageWindowChatMemory.builder()
                .maxMessages(10)
                .id(memoryId)
                .chatMemoryStore(mongdbChatMemoryProvider)  // 设置自定义的聊天记忆存储器
                .build();
    }



    /**
     * 创建一个聊天记忆提供者，用于创建聊天记忆,区分聊天记忆
     * @return
     */
    @Bean
    public ChatMemoryProvider chatAgentMemoryProvider(){
        return memoryId -> MessageWindowChatMemory.builder()
                .maxMessages(20)
                .id(memoryId)
                .chatMemoryStore(aiChatAgentMemoryProvider)  // 设置自定义的聊天记忆存储器
                .build();
    }


}
